<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>  
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="renderer" content="webkit">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>合同基础信息列表</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
	<div class="searchArea">
		<form id="baseContConfigForm">
			<div class="fieldset1 tabel_col clearFix">
				<div class="fieldBox col_50">
					<div class="label">合同层级</div>
					<div class="field">
						<input name="contLvl" id="contLvl" type="text" ltype="combobox" placeholder="请选择"  validate="{required:true}"/>
					</div>
				</div>
				<div class="fieldBox col_50" >
					<div class="label">主合同编码</div>
					<div class="field">
						<input name="pContCd" id="pContCd" type="text" class="ui-textbox"/>
					</div>
				</div>
				<div class="fieldBox col_50" >
					<div class="label">合同编码</div>
					<div class="field">
						<input name="contCd" id="contCd" type="text" class="ui-textbox" validate="{required:true}"/>
					</div>
				</div>
				<div class="fieldBox col_50">
					<div class="label">合同名称</div>
					<div class="field">
						<input name="contNm" id="contNm" type="text" class="ui-textbox"/>
					</div>
				</div>
				<div class="fieldBox col_50" >
					<div class="label">签署方式</div>
					<div class="field">
						<input name="signWayCd" id="signWayCd" type="text" ltype="combobox" placeholder="请选择"  validate="{required:true}"/>
					</div>
				</div>
				<div class="fieldBox col_50" >
					<div class="label">签署信息</div>
					<div class="field">
						<input name="signInfo" id="signInfo" type="text" class="ui-textbox"/>
					</div>
				</div>
				<div class="fieldBox col_50">
					<div class="label">合同类型</div>
					<div class="field">
						<input name="contTyp" id="contTyp" type="text" ltype="combobox" placeholder="请选择"  validate="{required:true}"/>
					</div>
				</div>
				<div class="fieldBox col_50" >
					<div class="label">签署节点</div>
					<div class="field">
						<input name="signNode" id="signNode" type="text" ltype="combobox" placeholder="请选择"  validate="{required:true}"/>
					</div>
				</div>
				<div class="fieldBox col_50">
					<div class="label">签署角色</div>
					<div class="field">
						<input name="signRole" id="signRole" type="text" ltype="combobox" placeholder="请选择"  validate="{required:true}"/>
					</div>
				</div>
				<div class="fieldBox col_50" >
					<div class="label">取值模板</div>
					<div class="field">
						<input name="valRule" id="valRule" type="text" ltype="combobox" placeholder="请选择" />
					</div>
				</div>
				<div class="fieldBox col_50">
					<div class="label">是否配置取值</div>
					<div class="field">
						<input name="isVal" id="isVal" type="text" ltype="combobox" placeholder="请选择"  validate="{required:true}"/>
					</div>
				</div>
				<div class="fieldBox col_50">
					<div class="label">生成维度</div>
					<div class="field">
						<input name="contDim" id="contDim" type="text" ltype="combobox" placeholder="请选择"  validate="{required:true}"/>
					</div>
				</div>
				<div class="fieldBox col_50" >
					<div class="label">是否最后一台车生成</div>
					<div class="field">
						<input name="isLast" id="isLast" type="text" ltype="combobox" placeholder="请选择"  validate="{required:true}"/>
					</div>
				</div>
				<div class="fieldBox col_100" >
					<div class="label">合同描述</div>
					<div class="field">
						<textarea name="contDesc" id="contDesc" rows="4"
								  class="ui-textarea l-textarea" style="width: 80%" value=""></textarea>
					</div>
				</div>
			</div>
			<div class="btnsBox">
				<c:if test="${detailFlag == true}">
					<span id="saveContConfig" class="sq-button sq-button-round" onclick="saveContConfig()">保存</span>
					<span id="cancelBtn" class="sq-button sq-button-round" onclick="cancelBtn()">取消</span>
				</c:if>
			</div>
		</form>
	</div>
</div>

<script type="text/javascript">

	var id = '${id}';
	var detailFlag = '${detailFlag}';

	$(function () {
		init();
		initForm();
	
		
		if(!detailFlag) {
			$("#saveContConfig").hide();
			$("#cancelBtn").hide();
			$("#baseContConfigForm").attr("readOnly", true);
			if(liger.get("contCd")&&liger.get("contCd")!="undefined"){
				liger.get("contCd").setDisabled(true);
			}
		}
		var baseContConfigForm = liger.get("baseContConfigForm");
		baseContConfigForm.setData({
			contLvl: '${contConfigVO.contLvl}',
			pContCd: '${pContCd}',
			contCd: '${contConfigVO.contCd}',
			contNm: '${contConfigVO.contNm}',
			signWayCd: '${contConfigVO.signWayCd}',
			signInfo: '${contConfigVO.signInfo}',
			contTyp:'${contConfigVO.contTyp}',
			signNode: '${contConfigVO.signNode}',
			signRole: '${contConfigVO.signRole}',
			valRule: '${contConfigVO.valRule}',
			isVal: '${contConfigVO.isVal}',
			contDim:'${contConfigVO.contDim}',
			isLast: '${contConfigVO.isLast}',
			contDesc: '${contConfigVO.contDesc}'
		});
		
	});
	
	function init(){


		contLvlComBox = $("#contLvl").ligerComboBox({
			url:'<%=path%>/system/sysdictionary/getSysDic.do',
			parms:{ orgCd: "0000", sysCd: "11000",codeGroup:"CONT003" },
			ajaxType:'GET',
			//value:$("#insCode").val(),
			valueField: 'key',
			textField:'value',
			onSuccess: function(data){
				if(data && !liger.get("contLvl").getValue()){
					liger.get("contLvl").setValue(data[0].key);
				}
			}
		});



		// 初始化合同签署方式
		$.getJSON('<%=path%>/system/sysdictionary/getSysDic.do', { orgCd: "0000", sysCd: "11000",codeGroup:"CONT004" },
				function(json){
					$("#signWayCd").ligerComboBox({
						data: json,
						valueField: 'key',
						textField:'value'
					});
					if(json && !liger.get("signWayCd").getValue()){
						liger.get("signWayCd").setValue(json[0].key);
					}
				}
		);
		// 初始化合同类型
		$.getJSON('<%=path%>/system/sysdictionary/getSysDic.do', { orgCd: "0000", sysCd: "11000",codeGroup:"CONT001" },
				function(json){
					$("#contTyp").ligerComboBox({
						data: json,
						valueField: 'key',
						textField:'value'
					});
					if(json && !liger.get("contTyp").getValue()){
						liger.get("contTyp").setValue(json[0].key);
					}
				}
		);
		// 初始化合同签署节点
		$("#signNode").ligerComboBox({
						url:'<%=path%>/system/sysdictionary/getSysDic.do',
						//data: json,
						ajaxType:'GET',
						parms:{ orgCd: "0000", sysCd: "11000",codeGroup:"CONT002" },
						valueField: 'key',
						textField:'value'
					});
		// 初始化合同签署角色
		 $("#signRole").ligerComboBox({
			 url:'<%=path%>/system/sysdictionary/getSysDic.do',
				ajaxType:'GET',
				parms:{ orgCd: "0000", sysCd: "11000",codeGroup:"CONT006" },
						isShowCheckBox: true, 
			    		isMultiSelect: true,
						valueField: 'key',
						textField:'value'
					}); 
		// 初始化合同取值规则
		$.getJSON('<%=path%>/system/sysdictionary/getSysDic.do', { orgCd: "0000", sysCd: "11000",codeGroup:"CONT005" },
				function(json){
					$("#valRule").ligerComboBox({
						data: json,
						valueField: 'key',
						textField:'value'
					});
				}
		);
		// 初始化合同生成维度
		$.getJSON('<%=path%>/system/sysdictionary/getSysDic.do', { orgCd: "0000", sysCd: "11000",codeGroup:"CONT007" },
				function(json){
					$("#contDim").ligerComboBox({
						data: json,
						valueField: 'key',
						textField:'value'
					});
				}
		);
		// 初始化合同是否取值，是否最后一台车生成
		$.getJSON('<%=path%>/system/sysdictionary/getSysDic.do', { orgCd: "0000", sysCd: "11000",codeGroup:"SYS0021" },
				function(json){
					$("#isVal").ligerComboBox({
						data: json,
						valueField: 'key',
						textField:'value'
					});
					$("#isLast").ligerComboBox({
						data: json,
						valueField: 'key',
						textField:'value'
					});
					if(json && !liger.get("isLast").getValue()){
						liger.get("isLast").setValue(json[0].key);
					}
				}
		);
		
	}

	function initForm(){
		form1 = $("#baseContConfigForm").ligerForm({
			validate: true
		});
	};
	
	//取消
	function cancelBtn(){
		var TAB=top.mainApp.parentTab;
		var currentTabid=TAB.getSelectedTabItemID();
		top.tab.removeTabItem(currentTabid);
	}

	function saveContConfig(){
		// form 必填校验
		if (!form1.valid()) {
			$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO,SQ_type: "warning"});
			return;
		}
		// 业务逻辑校验
		var contLvl = liger.get("contLvl").selectedValue;
		if(contLvl == '1'){
			var pContCd = $("#pContCd").val();
			if (StringUtils.isEmpty(pContCd)|| pContCd == undefined) {
				$("#pContCd").css({"border":"1px solid red"});
				$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO,SQ_type: "warning"});
				return;
			}
		}
		var signWayCd = liger.get("signWayCd").selectedValue;
		if(signWayCd == '00' || signWayCd == '01' || signWayCd == '03' || signWayCd == '04'){
			var signInfo = $("#signInfo").val();
			if (StringUtils.isEmpty(signInfo)|| signInfo == undefined) {
				$("#signInfo").css({"border":"1px solid red"});
				$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO,SQ_type: "warning"});
				return;
			}
		}
		var isVal = liger.get("isVal").selectedValue;
		if(isVal == '1' ){
			var valRule = liger.get("valRule").selectedValue;
			if (StringUtils.isEmpty(valRule)|| valRule == undefined) {
				$("#valRule").css({"border":"1px solid red"});
				$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO,SQ_type: "warning"});
				return;
			}
		}
		var data = liger.get("baseContConfigForm").getData();//获取表单数据
		data["id"] = '${id}';
		var wait_dialog;
		$.ajax({
			type: 'post',
			dataType:'json',
			data:data,
			url: '<%=path%>/cont/config/saveContConfig.do',
			beforeSend: function () {
				wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
			},
			success:function(msg){
				wait_dialog.close();
				if(msg.success == 1){
					top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
				}else{
					top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
				}
			}
		});
	}

</script>

</body>
</html>